package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.framework.exception.AppRuntimeException;
import com.boss.salary.service.IAgencySalaryService;
import com.boss.salary.service.IPersonBatchAddService;
import com.boss.salary.vo.AgencySalaryVO;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping(value = "/PersonBatchAddController")
public class PersonBatchAddController extends BasicinfoBaseController {
    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(ExcelController.class);

    @Autowired
    private IAgencySalaryService service;

    @Autowired
    private IPersonBatchAddService personBatchAddService;


    /**
     * 新增人员批量插入
     */
    @PostMapping("/personBatchImport")
    public ApiResultDTO personBatchImport(@RequestHeader("X-Token") String tokenid,
                                          @RequestParam("agencyId") String agencyId,
                                          @RequestParam("file") MultipartFile file){
        try {
//            System.out.println("开始时间："+DateUtils.getCurrentTimeStamp());
            UserDTO userDTO = getUser(tokenid);
            List<AgencySalaryVO> exccelColumnName = service.getExccelColumnName(userDTO);
            String province = userDTO.getProvince();
            personBatchAddService.Read(file,province,exccelColumnName,agencyId);
            return ApiResultDTO.success();
        } catch (AppRuntimeException e){
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, e.getMessage());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "导入失败");
        }

    }


}
